home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9824 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: seagull.rtd.com!collins
  2. From: collins@RTD.COM (Ronald Collins)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Standard question - pointer initialization
  5. Date: 13 Mar 1996 20:48:52 GMT
  6. Organization: RTD Internet Access
  7. Message-ID: <4i7cbl$5da@baygull.rtd.com>
  8. References: <4hk9un$906@hammer.msfc.nasa.gov> <4hl6rr$nde@news.xs4all.nl> <313E6028.1C19@ix.netcom.com> <4hnpsl$g8c@hacgate2.hac.com> <4hq9hsINN998@keats.ugrad.cs.ubc.ca>
  9. NNTP-Posting-Host: seagull.rtd.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Kazimir Kylheku (c2a192@ugrad.cs.ubc.ca) wrote:
  13. : In article <4hnpsl$g8c@hacgate2.hac.com>,
  14. : Ron Collins <collins@thor.tu.hac.com> wrote:
  15. : >Norman Bullen (nbullen@ix.netcom.com) wrote:
  16. : >[snip]
  17. : >
  18. : >: And there is no point in initializing a pointer when its declared if you 
  19. : >: don't know at that point what an appropriate value might be. Use of a 
  20. : >: pointer that has been initialized with an inappropriate value can be just 
  21. : >: as bad for the program as using an uninitialize pointer.
  22. : >
  23. : >The popular convention (when initializing pointers) is to set them to
  24. : >NULL.  This is the appropriate value to use when checking for invalid
  25. : >pointer usage.
  26.  
  27. : This is not a popular convention, but something that is demanded by the
  28. : language standard. A static uninitialized pointer shall take on a value that
  29. : corresponds to a null pointer, whatever that bit pattern is.
  30.  
  31. I know this is the requirement for static variables.  But I beleive
  32. (I could be wrong) that the original question referred to automatic
  33. variables, for which the standard imposes no such requirement.
  34.  
  35. [snip]
  36.  
  37. : By the way, null pointers are not for checking for incorrect pointer usage. It
  38. : is obviously legal and useful for a pointer to have a null value. Such a value
  39. : is guaranteed to always be distinct from a pointer which references an actual
  40. : object.
  41. : -- 
  42.  
  43. A NULL pointer is the _one_ value guaranteed to be illegal to dereference..  
  44. Although not it's primary purpose, it seems ready-made to trap for 
  45. debugging purposes.
  46.  
  47.             -- collins --
  48.  
  49.